/**
 * @class refrigeratory.win_changepassword
 * @extends Ext.Panel
 *

 *
 */
 
// create namespace
Ext.ns('refrigeratory');

/**
 * Creates new refrigeratory.win_changepassword
 * @constructor
 * @param {Object} config A config object
 */
refrigeratory.win_changepassword = Ext.extend(Ext.Window, {
	
    url: refrigeratory.REQUEST_URL

    ,initComponent:function() {
 
        // hard coded config (it cannot be changed while instantiating)
        // {{{
        var config = {        	
        	title: this.titleText
        	,id : 'win_changepassword'
        	,width: 300,
	        height:170,
	        minWidth: 300,
	        minHeight: 170,
	        maxWidth: 300,
	        maxHeight: 170,
	        layout: 'fit',
	        plain:true,
	        bodyStyle:'padding:5px;',
	        buttonAlign:'center',
	        closeAction: 'close',
	        items: this.createFpPassword(),
	        buttons: this.createButtons()
        }; // eo config object
 
        // apply config
        Ext.apply(this, Ext.apply(this.initialConfig, config));
        // }}}
 
        // call parent
        refrigeratory.win_changepassword.superclass.initComponent.apply(this, arguments);
 
        // parent call post-processing, e.g. install event handlers
 
    } // eo function initComponent

    ,onRender:function() {
     
        // parent call pre-processing
 
        // call parent
        refrigeratory.win_changepassword.superclass.onRender.apply(this, arguments);
 
        // parent call post-processing, e.g. install event handlers on rendered components
        //this.add();
       // this.doLayout();
 
    } // eo function onRender
    
    // 需本地化的文本
    ,titleText: 'Change Password'
    
    // private
    ,createFpPassword: function(){
    	var o = this.fpPassword = new Ext.form.FormPanel({
	        baseCls: 'x-plain',
	        url:'get.php',
	        defaultType: 'textfield',
	        items: this.createFpPasswordItem()
	    });
	    return o;
    }
    
    // private
    ,createButtons: function(){
    	this.btnSubmit = new Ext.Button({
    		text: "确定"
    		,handler: this.onBtnSubmitClick.createDelegate(this)
    	});
    	this.btnCancel = new Ext.Button({
    		text: "取消"
    		,handler: this.onBtnCancelClick.createDelegate(this)
    	});
    	return [this.btnSubmit, this.btnCancel];
    }
    
    //private
    ,createFpPasswordItem: function(){
    	this.txtOldPass = new Ext.form.TextField({
            name: 'oldpass',
            fieldLabel: '旧密码',
            inputType: 'password',
            anchor:'100%'
        });
        this.txtNewPass = new Ext.form.TextField({
            name: 'newpass',
            fieldLabel: '新密码',
            inputType: 'password',
            anchor:'100%'
        });
        this.txtConfirmPass = new Ext.form.TextField({
            name: 'confirmpass',
            fieldLabel: '确认新密码',
            inputType: 'password',
            anchor:'100%'
        });
        return [this.txtOldPass, this.txtNewPass, this.txtConfirmPass];
    }
    
    
    //private
    ,onBtnSubmitClick: function(){
        var o = this.txtOldPass;
        var n = this.txtNewPass;
        var c = this.txtConfirmPass;
        if (!o.getValue() || !n.getValue() || !c.getValue() ){
        	Ext.MessageBox.alert('Warning','Please input password!');
        	return;
        }
        else if (n.getValue()!=c.getValue()){
        	Ext.MessageBox.alert('Warning','New passwords does not match!');
        	return;
        }
        else if (n.getValue().length < 3){
        	Ext.MessageBox.alert('Warning','New password should be longer than 3 letters!');
        	return;
        }
    	this.fpPassword.getForm().submit({
    		url: "get.php"
    		,params: {
    			action: "user"
    			,operation: "change_password"
    		}
			,waitTitle: "Please wait"
			,waitMsg: "Saving..."
			,success: (function(){
				this.close();
				Ext.MessageBox.alert('Tip',"Change password successfully!");
			}).createDelegate(this)
			,failure: function(form, action){
				Ext.MessageBox.alert('Warning',action.result.info);
			}
    	});
    }
    
    //private
    ,onBtnCancelClick: function(){
    	this.close();
    }
}); // eo extend
 
// register xtype
Ext.reg('win_changepassword', refrigeratory.win_changepassword); 
// eof